﻿#pragma once
/**
* Copyright (c) 2014-2018 dustpg   mailto:dustpg@gmail.com
*
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation
* files (the "Software"), to deal in the Software without
* restriction, including without limitation the rights to use,
* copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following
* conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*/

#include "ui_control.h"
//#include "../util/ui_double_click.h"

// ui namespace
namespace LongUI {
    // tree
    class UITree;
    // treerow
    class UITreeRow;
    // treechildren
    class UITreeChildren;
    // treeitem control
    class UITreeItem : public UIControl {
        // super class
        using Super = UIControl;
    protected:
        // ctor
        UITreeItem(UIControl* parent, const MetaControl&) noexcept;
    public:
        // class meta
        static const  MetaControl   s_meta;
        // dtor
        ~UITreeItem() noexcept;
        // ctor
        UITreeItem(UIControl* parent = nullptr) noexcept : UITreeItem(parent, UITreeItem::s_meta) {}
    public:
        // is selected?
        auto IsSelected() const noexcept { return m_oStyle.state.selected; }
        // select to this
        //void SelectToThis() noexcept;
        // select this
        //void Select(bool exsel) noexcept;
        // get row
        auto GetRow() const noexcept { return m_pRow; }
        // get tree node
        auto GetTreeNode() const noexcept { return m_pTree; }
        // get tree children
        auto GetTreeChildren() const noexcept { return m_pChildren; }
        // tree children changed
        void TreeChildrenChanged(bool has_child) noexcept;
        // tree children closed
        void TreeChildrenOpenClose(bool open) noexcept;
        // tree children level offset
        void TreeLevelOffset(float offset) noexcept { m_fLevelOffset = offset; }
        // set tree root as this
        void AsSameTreeTo(const UITreeItem& x) noexcept { m_pTree = x.m_pTree; }
    public:
        // do normal event
        auto DoEvent(UIControl* sender, const EventArg& e) noexcept->EventAccept override;
        // do mouse event
        //auto DoMouseEvent(const MouseEventArg& e) noexcept->EventAccept override;
        // update, postpone change some data
        void Update() noexcept override;
        // render this control only, [Global rendering and Incremental rendering]
        //void Render() const noexcept override;
        // recreate/init device(gpu) resource
        //auto Recreate() noexcept->Result override;
    protected:
        // add child
        void add_child(UIControl& child) noexcept override;
#ifdef LUI_ACCESSIBLE
        // accessible api
        auto accessible(const AccessibleEventArg& args) noexcept->EventAccept override;
#endif
        // relayout base
        void relayout_base(UIControl* head) noexcept;
        // refresh minsize
        void refresh_minsize(UIControl* head) noexcept;
    protected:
        // tree root
        UITree*                 m_pTree = nullptr;
        // tree row
        UITreeRow*              m_pRow = nullptr;
        // tree children
        UITreeChildren*         m_pChildren = nullptr;
        // level offset
        float                   m_fLevelOffset = 0.f;
        // marked selected
        bool                    m_bMarkdSel = false;
    private:
    };
    // get meta info for UITreeItem
    LUI_DECLARE_METAINFO(UITreeItem);
}
